// pages/map/map.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        lng: 0,
        lat: 0,
        markers:[],
        circles:[]
    },

    drawCircle(center) {
        var cirle = {
            latitude :center.latitude || center.lat || center[0],
            longitude :center.longitude || center.lng || center[1],
            radius:100,
            strokeWidth:1,
            strokeColor:'#FF00FF'
        };
        this.setData({
            circles:[cirle]
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.getLocation({
            type: 'gcj02',
            success:(ret)=>{
                console.log(ret)
                var marker = {
                    id:1,
                    longitude:ret.longitude,
                    latitude:ret.latitude,
                    title: "I am here",
                    // iconPath :"/assets/pin-red.png",
                    width:50,height:50
                }
                var longitude = ret.longitude;
                var latitude = ret.latitude;
                const key = 'CUABZ-QRALW-ZJCRC-RYLET-E75SE-FLFMJ';
                wx.request({
                    type: 'gcj02',
                    url:'https://apis.map.qq.com/ws/geocoder/v1',
                    data:{
                        key:key,
                        location:latitude+','+longitude
                    },success(res){
                        var address = res.data.result.address
                        var name = res.data.result.formatted_addresses.recommend
                        // const {recommend} = res.data.result.formatted_addresses
                        console.log(address,name)
                    },fail(res){
                        console.log(res)
                    }
                })
                this.setData({
                    lng:ret.longitude,
                    lat:ret.latitude,
                    markers:[marker]
                })
                this.drawCircle(ret);
            }
        })
    },

    sign(){
        
    }
})